home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Frameworks / Argus Frameworks 2.1 / Argus Libraries 2.1 / Argus Standards / ArgusHelp.cp < prev    next >
Text File  |  1996-01-02  |  12KB  |  386 lines

  1. /**********************************************************************
  2.  
  3.     ArgusHelp.cp
  4.  
  5. ***********************************************************************/
  6.  
  7. /*
  8.     This library provides a simple function call to display a dialog
  9.     which displays some help or general information about the
  10.     application.  Reads text from TEXT resource ID identified by
  11.     HELP_TEXT.
  12.  
  13.     Functions Include:
  14.  
  15.       MyHelpDialog            Standard Argus Help Dialog
  16.       
  17.       // Semi-private
  18.       MyHelpEventFilter
  19.       SetUpHelpTEWindow
  20.       MyHelpDoContent
  21.       FnTE_AdjustText
  22.       FnTE_SetToCursorPos
  23.       FnTE_ScrollProc
  24. */
  25.  
  26.  
  27. /********** Includes */
  28. #include <Dialogs.h>
  29. #include "Fn_Prototypes.h"
  30.  
  31. #include "MainWindow.h"    // may need to modify
  32.  
  33.  
  34. /********** Defines */
  35. #define HELP_DLOG      598
  36. #define HELP_TEXT      598
  37. #define NIL_PTR        0L
  38. #define ALLOCATE_MEM   0
  39. #define IN_FRONT       (WindowPtr)-1L
  40. #define OK_BUTTON      1
  41. #define PR_BUTTON      2
  42. #define SV_BUTTON      3
  43. #define RETURN_KEY     13
  44. #define ENTER_KEY      3
  45. #define VISUAL_DELAY   8  // standard is 8 ticks
  46.  
  47.  
  48. TEHandle             te = 0L;
  49. ControlHandle        vScroll = 0L;
  50. extern TEHandle      *tempTEHptr;
  51. extern ControlHandle *tempVScrollptr;
  52. Str255               okButtonStr;
  53. Str255               printButtonStr;
  54. Str255               saveButtonStr;
  55.  
  56.  
  57. /********** Prototypes */
  58. Boolean        MyHelpDialog( void );
  59. pascal Boolean MyHelpEventFilter(  DialogPtr     theDialog,
  60.                                    EventRecord   *theEvent,
  61.                                    short         *itemHit );
  62. Boolean        SetUpHelpTEWindow(  WindowPtr     w,
  63.                                    Boolean       hasGrowIcon,
  64.                                    Boolean       wordWrap,
  65.                                    short         font,
  66.                                    short         textSize,
  67.                                    short         textInsetPixels,
  68.                                    // results //
  69.                                    TEHandle      *te,
  70.                                    ControlHandle *vScroll );
  71. void           MyHelpDoContent(    WindowPtr     w, 
  72.                                    EventRecord   *e,
  73.                                    TEHandle      *te,
  74.                                    ControlHandle *vScroll,
  75.                                    short         *itemHit );
  76. extern void    FnTE_AdjustText(    TEHandle      *te, 
  77.                                    ControlHandle *vScroll );
  78. extern void    FnTE_SetToCursorPos(TEHandle      *te,
  79.                                    ControlHandle *vScroll );
  80. extern pascal void FnTE_ScrollProc(ControlHandle theControl,
  81.                                    short         theCode );
  82.  
  83.  
  84. /********** MyHelpDialog */
  85.  
  86. Boolean MyHelpDialog( void )
  87. {
  88.     WindowPtr     docWindow;
  89.     DialogPtr     dialog;
  90.     Boolean       done;
  91.     Boolean       result;
  92.     short         itemHit;
  93.     short         itemType;
  94.     Handle        itemHandle;
  95.     Rect          itemRect;
  96.     EventRecord   theEvent;
  97.     long          finalTicks;
  98.     THPrint       pPrintH;
  99.     short         vRef;
  100.     short         refNum;
  101.  
  102.     result = FALSE;
  103.     pPrintH = (TPrint **)NewHandle( sizeof( TPrint ) );
  104.     PrintDefault( pPrintH );
  105.     
  106.     docWindow = FrontWindow();
  107.     if( docWindow != NIL_PTR )
  108.         MyDoDeactivateWindow( docWindow );
  109.  
  110.     dialog = GetNewDialog( HELP_DLOG, ALLOCATE_MEM, IN_FRONT );
  111.  
  112.     if( dialog == NIL_PTR )
  113.         return( result );
  114.  
  115.     /* AdjustMenus_(); */
  116.     SetUpHelpTEWindow( (WindowPtr)dialog, FALSE, TRUE, monaco, 9,
  117.         4, &te, &vScroll );
  118.     FnTE_GetTEXT( HELP_TEXT, &te, &vScroll );
  119.     
  120.     ShowWindow( dialog );
  121.     FnTE_UpdateWindow( (WindowPtr)dialog, &te, FALSE );
  122.     FnTE_FrameRect( (WindowPtr)dialog, &te, 4 );
  123.     FnMisc_FrameButton( dialog, OK_BUTTON );
  124.     
  125.     GetDItem( dialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
  126.     GetCTitle( (ControlHandle)itemHandle, okButtonStr );
  127.     GetDItem( dialog, PR_BUTTON, &itemType, &itemHandle, &itemRect );
  128.     GetCTitle( (ControlHandle)itemHandle, printButtonStr );
  129.     GetDItem( dialog, SV_BUTTON, &itemType, &itemHandle, &itemRect );
  130.     GetCTitle( (ControlHandle)itemHandle, saveButtonStr );
  131.     
  132.     done = FALSE;
  133.     while( done == FALSE )
  134.     {
  135.         ModalDialog( &MyHelpEventFilter, &itemHit );
  136.  
  137.         switch( itemHit )
  138.         {
  139.             case OK_BUTTON:
  140.                 result = TRUE;
  141.                 done = TRUE;
  142.                 break;
  143.             case PR_BUTTON:
  144.                 result = TRUE;
  145.                 FnIO_PrintTERecord( &te, &pPrintH );
  146.                 break;
  147.             case SV_BUTTON:
  148.                 result = TRUE;
  149.                 FnIO_SaveAsTextFile( &te,"\pHelp Text",&vRef,&refNum );
  150.                 break;
  151.             default:
  152.                 break;
  153.         }
  154.      }
  155.  
  156.     DisposeHandle( (Handle)te );
  157.     DisposeControl( vScroll );
  158.     DisposeHandle( (Handle)pPrintH );
  159.     DisposDialog( dialog );
  160.  
  161.     return( result );
  162. }
  163.  
  164.  
  165. /********** PASCAL MyHelpEventFilter */
  166.  
  167. pascal Boolean MyHelpEventFilter( DialogPtr    theDialog,
  168.                                   EventRecord  *theEvent,
  169.                                   short        *itemHit )
  170. {
  171.     short          thePart;
  172.     char           key;
  173.     short          itemType;
  174.     Handle         itemHandle;
  175.     Rect           itemRect;
  176.     long           finalTicks;
  177.     Rect           dragRect;
  178.     Boolean        result;
  179.     Point          theLocation;
  180.     WindowPtr      theWindow;
  181.     
  182.     result = FALSE;
  183.     dragRect = qd.screenBits.bounds;
  184.     
  185.         switch( (*theEvent).what )
  186.         {
  187.             case mouseDown:
  188.                 thePart = FindWindow( (*theEvent).where, &theWindow );
  189.                 if( theWindow == theDialog )
  190.                 {
  191.                     switch( thePart )
  192.                     {
  193.                         case inDrag:
  194.                             DragWindow( theDialog,
  195.                                         (*theEvent).where,
  196.                                         &dragRect );
  197.                             result = TRUE;
  198.                             break;
  199.                         case inContent:
  200.                             if( theDialog == FrontWindow() )
  201.                             {
  202.                                 MyHelpDoContent( (WindowPtr)theDialog,
  203.                                     theEvent, &te, &vScroll, itemHit );
  204.                                 result = TRUE;
  205.                             }
  206.                             break;
  207.                         default:
  208.                             break;
  209.                      }
  210.                  }
  211.                 break;
  212.             case keyDown:
  213.             case autoKey:
  214.                 key = (*theEvent).message & charCodeMask;
  215.                 if( (key == RETURN_KEY) || (key == ENTER_KEY) )
  216.                 {
  217.                     GetDItem( theDialog,
  218.                               OK_BUTTON,
  219.                               &itemType,
  220.                               &itemHandle,
  221.                               &itemRect );
  222.                     HiliteControl( (ControlHandle)itemHandle,
  223.                                    inButton );
  224.                     Delay( VISUAL_DELAY, &finalTicks );
  225.                     HiliteControl( (ControlHandle)itemHandle, 0 );
  226.                     *itemHit = OK_BUTTON;
  227.                     result = TRUE;
  228.                 }
  229.                 /* Handle other keyboard equivalents here */
  230.                 break;
  231.             case updateEvt:
  232.                 if( (WindowPtr)(*theEvent).message != theDialog )
  233.                 {
  234.                     MyDoUpdateWindow( (WindowPtr)(*theEvent).message );
  235.                 }
  236.                 else
  237.                 {
  238.                     FnTE_UpdateWindow( theDialog, &te, FALSE );
  239.                     FnTE_FrameRect( (WindowPtr)theDialog, &te, 4 );
  240.                     FnMisc_FrameButton( theDialog, OK_BUTTON );
  241.                 }
  242.                 break;
  243.             case activateEvt:
  244.                 if( (WindowPtr)(*theEvent).message != theDialog )
  245.                 {
  246.                     /*
  247.                     DoActivate_( (WindowPtr)(*theEvent).message,
  248.                                  ((*theEvent).modifiers & activeFlag),
  249.                                  *theEvent );
  250.                     */
  251.                  }
  252.                  break;
  253.             default:
  254.                  break;
  255.         }
  256.         
  257.     return( result );
  258. }
  259.  
  260. /********** SetUpHelpTEWindow */
  261.  
  262. Boolean SetUpHelpTEWindow(
  263.     WindowPtr  w,
  264.     Boolean    hasGrowIcon,
  265.     Boolean    wordWrap,
  266.     short      font,
  267.     short      textSize,
  268.     short      textInsetPixels,
  269.     // results //
  270.     TEHandle      *te,
  271.     ControlHandle *vScroll )
  272. /*
  273.     FnSetUpWindow takes information you supply about a window
  274.     and it's default text parameters then returns a TEHandle to
  275.     a text pane that fills the window and a ControlHandle to
  276.     a scroll bar that is located at the right of the window.
  277.     Returns FALSE if error detected during routine.
  278. */
  279. {
  280.     Rect       destRect, viewRect;
  281.     Rect       vSBarRect;
  282.     GrafPtr    oldPort;
  283.     int        SBarWidth = 15;
  284.     int        inset = 10;
  285.     int        bottomInset = 46;
  286.  
  287.     // define basic te stuff
  288.     GetPort( &oldPort );
  289.     SetPort( w );
  290.     TextFont( font );
  291.     TextSize( textSize ); 
  292.  
  293.     // set scroll bar rect       
  294.     vSBarRect = (*w).portRect;
  295.     vSBarRect.left = vSBarRect.right - SBarWidth - inset;
  296.     vSBarRect.right = vSBarRect.right + 1 - inset;
  297.     vSBarRect.top = vSBarRect.top - 1 + inset;
  298.     if( hasGrowIcon )
  299.         vSBarRect.bottom = vSBarRect.bottom - 14 - bottomInset;
  300.     else
  301.         vSBarRect.bottom = vSBarRect.bottom - bottomInset;
  302.     
  303.     // create new control      
  304.     *vScroll = NewControl( w, &vSBarRect, "\p", 1, 0, 0, 0,
  305.         scrollBarProc, 0L);
  306.     if( *vScroll == NULL )
  307.         return FALSE;
  308.     
  309.     // define te view and dest rects
  310.     viewRect = w->portRect;
  311.     viewRect.right = vSBarRect.left;
  312.     viewRect.bottom = vSBarRect.bottom;
  313.     viewRect.top = vSBarRect.top;
  314.     viewRect.left = viewRect.left + inset;
  315.     InsetRect(&viewRect, textInsetPixels, textInsetPixels);
  316.     destRect = viewRect;
  317.         
  318.     // create new te record
  319.     *te = TENew( &destRect, &viewRect );
  320.     if( *te == NULL )
  321.         return FALSE;
  322.     if( wordWrap )
  323.         (***te).crOnly = 1;
  324.     else
  325.         (***te).crOnly = -1;
  326.     
  327.     SetPort( oldPort );
  328.     return TRUE;
  329. }
  330.  
  331.  
  332. /********** MyHelpDoContent */
  333.  
  334. void MyHelpDoContent( WindowPtr     w, 
  335.                       EventRecord   *e,
  336.                       TEHandle      *te,
  337.                       ControlHandle *vScroll,
  338.                       short         *itemHit )
  339. /*
  340.     Use this procedure when user clicks in content region of TE window.
  341.     Uses the TnTE_ScrollProc below to take care of scroll bar function.
  342.     Also uses FnTE_AdjustText function.
  343. */
  344. {
  345.     int                cntlCode;
  346.     ControlHandle      cntl, compareCntl;
  347.     int                pageSize;
  348.     GrafPtr            savePort;
  349.     
  350.     GetPort(&savePort);
  351.     SetPort(w);
  352.     
  353.     *itemHit = 0;
  354.  
  355.     GlobalToLocal(&e->where);
  356.     if( (cntlCode = FindControl(e->where, w, &cntl)) == inButton )
  357.     {
  358.         if( TrackControl( cntl, e->where, 0L ) )
  359.         {
  360.             if(EqualString((**cntl).contrlTitle,okButtonStr,0,0))
  361.                 *itemHit = OK_BUTTON;
  362.             if(EqualString((**cntl).contrlTitle,printButtonStr,0,0))
  363.                 *itemHit = PR_BUTTON;            
  364.             if(EqualString((**cntl).contrlTitle,saveButtonStr,0,0))
  365.                 *itemHit = SV_BUTTON;            
  366.         }
  367.     }
  368.     else if( cntlCode == inThumb )
  369.     {
  370.         TrackControl( cntl, e->where, 0L );
  371.         FnTE_AdjustText( te, vScroll );
  372.     }
  373.     else if( (cntlCode == inUpButton) ||
  374.              (cntlCode == inDownButton) ||
  375.              (cntlCode == inPageUp) ||
  376.              (cntlCode == inPageDown) )
  377.     {
  378.         tempTEHptr = te;
  379.         tempVScrollptr = vScroll;
  380.         TrackControl( cntl, e->where, FnTE_ScrollProc );
  381.     }
  382.  
  383.     SetPort(savePort);
  384. }
  385.  
  386. // End of File